/*
 * ChoiceNetPanel.java
 *
 * 
 */
package it.luigiarpino.alt2jsim.netpanel.transit;

import it.luigiarpino.alt2jsim.netpanel.flat.NetPanel;
import it.luigiarpino.alt2jsim.network.TransitStubNet;
import javax.swing.*;
import java.awt.*;
/**
 *
 * @author  Luigi Lorenzo Arpino 534/559
 */
public class SingleTransitNetPanel extends JPanel {
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 2119435406514295285L;
	private JComboBox jComboBoxScegliRete;
    private JLabel jLabelScegliRete;
    private String[] nomiNodi;
    private JPanel jPanelSouthPanel;
    private NetPanel netPanel;
    private TransitStubNet net;

    /**  */
    public SingleTransitNetPanel(TransitStubNet net_) {
        super();
        try { 
            javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());     
    	} 
    	catch(Exception e) { }
        this.net =net_;
        this.jComboBoxScegliRete=new JComboBox();
        this.nomiNodi=this.net.getTransitName();
        String[] model=new String[this.nomiNodi.length];
        for(int i=0;i<this.nomiNodi.length;i++){
            model[i]="  "+this.nomiNodi[i]+"  ";
        }
        this.jComboBoxScegliRete.setModel(new javax.swing.DefaultComboBoxModel(model));
        this.jComboBoxScegliRete.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
                ComboActionPerformed(evt);
            }
        });
        this.jLabelScegliRete=new JLabel("Seleziona rete transit da mostrare");
        this.jPanelSouthPanel=new JPanel(new FlowLayout());
        this.jPanelSouthPanel.add(this.jLabelScegliRete);
        this.jPanelSouthPanel.add(this.jComboBoxScegliRete);
        this.netPanel=new NetPanel(null ,"",null,NetPanel.ROUTER);
        this.setLayout(new BorderLayout());
        this.add(this.netPanel,BorderLayout.CENTER);
        this.add(this.jPanelSouthPanel,BorderLayout.SOUTH);
        this.ComboActionPerformed(null);
    }
    
    
    private void ComboActionPerformed(java.awt.event.ActionEvent evt) {
        String rete =new String(this.nomiNodi[this.jComboBoxScegliRete.getSelectedIndex()]);
        this.remove(this.netPanel);
        //String numeroNodi=String.valueOf(this.nomiNodi.length);
        String titolo=new String("Zoom della rete transit numero "+rete);
        this.netPanel=new NetPanel(this.net.getTransitMatrixOfNet(rete), titolo,this.net.getTransitNameOfNet(rete),NetPanel.TRANSIT_NODE);
        this.add(this.netPanel,BorderLayout.CENTER);
        this.validate();
    }
      
    
}
